//
//  BigNumber.hpp
//  BigNumber
//
//  Created by chenyh on 2021/2/19.
//

#ifndef BigNumber_hpp
#define BigNumber_hpp

#include <iostream>
#include <string.h>
using namespace std;
class BigNumber {
private:
    int * data;                    //存储转化后的整型数组
    string::size_type charLength;  //存储字符串长度
    int   arraySize;               //整型数组大小
public:
    /**构造函数*/
    BigNumber(string number) { //以输入的字符串构造大数据
        charLength = number.size(); //获取字符串数
        if (charLength % 4 == 0) {
            arraySize = charLength / 4;
        }else{
            arraySize = charLength/4+1;
        }
        data = new int(arraySize); //建立字符串转化为整数后的存储数组
        for (int i=0; i<arraySize; i++) {
            data[i] = 0;
        }
        string::size_type charPointer = charLength-1;
        int weight = 0; //设置进位权值
        for (int i=arraySize-1; i>=0; i--) {
            weight = 1;
            for (int j= 0; j<4; j++) {
                if (charPointer != 0) {
                    data[i] += (number[charPointer]-'0')*weight;
                    weight *= 10;
                    charPointer--;
                }else
                    break;
            }
        }
        data[0] += (number[0]-'0')*weight;
    }
    //构造函数，以所需的整数数组大小为参数
    BigNumber(int s)
    {
        data = new int(s);
        for (int i = 0; i<s; i++) {
            data[i] = 0;
        }
        arraySize = s;
    }
    ~BigNumber() {
//        delete data;
    }
    //获取表示大数的整型数组
    int * getData() {
        return data;
    }
    //获取数组大小
    int getArraySize() {
        return arraySize;
    }
    
};

#endif /* BigNumber_hpp */
